﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business;
using DataAccess;
using DTO;
using System.Data;
namespace Airplane
{
    public partial class TrangChu : System.Web.UI.MasterPage
    {
       
        protected void btnDangNhap_Click(object sender, EventArgs e)
        {
            KiemTraDangNhap();
        }

        protected void btnDangXuat_Click(object sender, EventArgs e)
        {
            Session["TrangThaiDangNhap"] = "ChuaDangNhap";
            Session["SoTheHoiVien"] = 0;
            MultiView1.ActiveViewIndex = 0;
        }

        public void KiemTraDangNhap()
        {
            XuLyDangNhap login = new XuLyDangNhap();
            KhachHang kh = new KhachHang();
            kh.TenTaiKhoan = txtThanhVien.Text;
            kh.MatKhau = txtMatKhau.Text;
            login.khachhang = kh;
            if (login.ThucThi() == 1)
            {
                Session["TrangThaiDangNhap"] = "DaDangNhap";
                lbThongBao.Text = "Đã đăng nhập thành công";
                Session["KhachHang"] = kh.TenTaiKhoan.ToString();                
                XuLyLayThongTinKhachHang thongtin = new XuLyLayThongTinKhachHang();
                thongtin.khachkhang.TenTaiKhoan = kh.TenTaiKhoan;
                thongtin.ThucThi();
                DataTable dt = thongtin.datatable;
                
               Session["HoTen"]= dt.Rows[0]["HoTen"].ToString();
               Session["SoTheHoiVien"] = dt.Rows[0]["SoTheHoiVien"].ToString();
               Session["GioiTinh"] = dt.Rows[0]["GioiTinh"];
               Session["DiaChi"] = dt.Rows[0]["DiaChi"];
               Session["NgaySinh"] = dt.Rows[0]["NgaySinh"];
               Session["Email"] = dt.Rows[0]["Email"];
               Session["DienThoai"] = dt.Rows[0]["DienThoai"];
               Session["SoGiayToTuyThan"] = dt.Rows[0]["SoGiayToTuyThan"];
               Session["LoaiGiayToTuyThan"] = dt.Rows[0]["LoaiGiayToTuyThan"];
               Session["NgayCap"] = dt.Rows[0]["NgayCap"];
               Session["NuocPhatHanh"] = dt.Rows[0]["NuocPhatHanh"];
               Session["QuocTich"] = dt.Rows[0]["QuocTich"];
               Session["TenTaiKhoan"] = dt.Rows[0]["TenTaiKhoan"];
               Session["EmailPhucHoi"] = dt.Rows[0]["EmailPhucHoi"];
               Session["MatKhau"] = dt.Rows[0]["MatKhau"].ToString();
               Session["SoDam"] = dt.Rows[0]["SoDam"];
               Session["HangHoiVien"] = dt.Rows[0]["HangHoiVien"];
               Session["SoCreditCard"] = dt.Rows[0]["SoCreditCard"];
               Session["LoaiCreditCard"] = dt.Rows[0]["LoaiCreditCard"];
               Session["NgayHetHanCredit"] = dt.Rows[0]["NgayHetHanCredit"];
               Session["SoTheHoiVien"] = dt.Rows[0]["SoTheHoiVien"];
               Response.Redirect("TrangChu.aspx");
            }
            else
                lbThongBao.Text = "Đăng Nhập Thất bại";
              
            
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if ((string)Session["TrangThaiDangNhap"]=="DaDangNhap")
            {
                MultiView1.ActiveViewIndex = 1;
                lbXinChao.Text = "Xin chao "  +Session["KhachHang"].ToString();
                
            }
            else
            {
                MultiView1.ActiveViewIndex = 0;
            }
         }

    }
}